package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author Pan Rundong
 * @Date 2023-03-09 14:05
 * @Desc 后台用户管理Controller
 */
@RestController
@RequestMapping("manage")
public class ManageController {
    @Autowired
    private ManageService manageService;

    /**
     * 用户分页查找
     *
     * @param page
     * @param pagesize
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize)
    {
        PageResult result = manageService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据用户Id
     * 查找详细信息
     *
     * @param userId
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @GetMapping("users/{userId}")
    public ResponseEntity findById(@PathVariable("userId") Long userId) {
        UserInfo userInfo = manageService.findById(userId);
        return ResponseEntity.ok(userInfo);
    }

    /**
     * 视频列表查询
     *
     * @param page
     * @param pagesize
     * @param uid
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @GetMapping("videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid)
    {
        PageResult result = manageService.findAllVideos(page, pagesize, uid);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询动态
     *
     * @param page
     * @param pagesize
     * @param uid
     * @param state
     * @return org.springframework.http.ResponseEntity
     * @Author Pan Rundong
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state) {
        PageResult result = manageService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    /**
     * 用户冻结
     *
     * @param map
     * @return org.springframework.http.ResponseEntity<java.lang.String>
     * @Author Pan Rundong
     */
    @PostMapping("users/freeze")
    public ResponseEntity<Map> freeze(@RequestBody Map map) {
        Map<String, String> stringMap = manageService.freeze(map);
        return ResponseEntity.ok(stringMap);
    }

    /**
     * 解冻
     *
     * @param map
     * @return org.springframework.http.ResponseEntity<java.util.Map>
     * @Author Pan Rundong
     */
    @PostMapping("users/unfreeze")
    public ResponseEntity<Map> unFreeze(@RequestBody Map map) {
        Map<String, String> stringMap = manageService.unFreeze(map);
        return ResponseEntity.ok(stringMap);
    }
}
